package com.gaoyang.task;

import com.gaoyang.domain.DianPingUser;
import com.gaoyang.domain.GongHuiUser;
import com.gaoyang.service.GonghuiUserService;
import com.gaoyang.service.ParamService;
import com.gaoyang.thread.GonghuiThread;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduledTasks4Gonghui {

    private Logger logger = LogManager.getLogger(ScheduledTasks4Gonghui.class);

    @Autowired
    private GonghuiTask task;

    @Autowired
    ParamService paramService;

    @Autowired
    GonghuiUserService userService;

    private String list_address = "http://app.bjzgh12351.org/mobile_3.0/api/service/list_no_con.jsp?token=EC9350ED11CDDF42160915640700B190&page=1&size=50";
    private String list_auth_address = "http://app.bjzgh12351.org/mobile_3.2/api/service/list.jsp?token=053C77744BA89118BA77451D865BEE3F&service_name=&search_type=1&district=undefined&district_type=undefined&category=0&begin_time=&is_reserve=0&gender=0&page=1&size=10&longitude=116.46315527376237&latitude=39.93705447027181";
    private String list_info_address = "http://app.bjzgh12351.org//mobile_3.0/api/service/batch-list.jsp?project_id=23459&service_name=&page=1&size=10&search_type=0&token=EC9350ED11CDDF42160915640700B190";

    GongHuiUser gonghui_gaoyang = null;
    GongHuiUser gonghui_wangyue = null;
    GongHuiUser gonghui_rongjiali = null;
    GongHuiUser gonghui_gaobaohong = null;
    GongHuiUser gonghui_wangzhiqiang = null;
    GongHuiUser gonghui_chenzhifei = null;
    GongHuiUser gonghui_liuyanmei = null;


//    @Scheduled(fixedRate = 1000)
    public void reportGonghuiInfo() throws Exception{
        //高洋
        if (gonghui_gaoyang == null) {
            DianPingUser gaoyang = userService.findUserByUserName("高洋");
//            String token_gaoyang = task.getLoginToken(gaoyang);
        gonghui_gaoyang = copyUser(gaoyang);
//        gonghui_gaoyang.setToken(token_gaoyang);
            gonghui_gaoyang.setToken("B3279703B29602E9D382723CADD79C6D");
        }

        //王悦
        if (gonghui_wangyue == null) {
            DianPingUser wangyue = userService.findUserByUserName("王悦");
//            String token_wangyue = task.getLoginToken(wangyue);
            gonghui_wangyue = copyUser(wangyue);
//            gonghui_wangyue.setToken(token_wangyue);
            gonghui_wangyue.setToken("12A1E66642F068903E8704D46AE20FDC");
        }

        //荣佳丽
        if (gonghui_rongjiali == null) {
            DianPingUser rongjiali = userService.findUserByUserName("荣佳丽");
//            String token_rongjiali = task.getLoginToken(rongjiali);
            gonghui_rongjiali = copyUser(rongjiali);
//            gonghui_rongjiali.setToken(token_rongjiali);
            gonghui_rongjiali.setToken("35469A9F7D89B567185C9FAD8F5F32D8");
        }

        //高宝鸿
        if (gonghui_gaobaohong == null) {
            DianPingUser gaobaohong = userService.findUserByUserName("高宝鸿");
//            String token_gaobaohong = task.getLoginToken(gaobaohong);
            gonghui_gaobaohong = copyUser(gaobaohong);
//            gonghui_gaobaohong.setToken(token_gaobaohong);
            gonghui_gaobaohong.setToken("7F578E67FCC24D94AF2B0E83B5424BD2");
        }

        //王志强
        if (gonghui_wangzhiqiang == null) {
            DianPingUser wangzhiqiang = userService.findUserByUserName("王志强");
//            String token_wangzhiqiang = task.getLoginToken(wangzhiqiang);
            gonghui_wangzhiqiang = copyUser(wangzhiqiang);
//            gonghui_wangzhiqiang.setToken(token_wangzhiqiang);
            gonghui_wangzhiqiang.setToken("498105944BB3D5E32685D1E17EFB612F");
        }

        //陈志飞
        if (gonghui_chenzhifei == null) {
            DianPingUser chenzhifei = userService.findUserByUserName("陈志飞");
//            String token_chenzhifei = task.getLoginToken(chenzhifei);
            gonghui_chenzhifei = copyUser(chenzhifei);
//            gonghui_chenzhifei.setToken(token_chenzhifei);
            gonghui_chenzhifei.setToken("61D7A223B8C1ABA64C4298EEC12532DD");

        }
        //刘燕梅
        if (gonghui_liuyanmei == null) {
            DianPingUser liuyanmei = userService.findUserByUserName("刘燕梅");
//            String token_liuyanmei = task.getLoginToken(liuyanmei);
            gonghui_liuyanmei = copyUser(liuyanmei);
//            gonghui_liuyanmei.setToken(token_liuyanmei);
            gonghui_liuyanmei.setToken("33E597C45A7BCA3C11C0BD570D80BDFC");

        }
        task.reportGonghuiListInfo(GonghuiThread.gonghui_actId, GonghuiThread.gonghui_count, gonghui_gaoyang, GonghuiThread.gonghui_firm_id);
        task.reportGonghuiListInfo(GonghuiThread.gonghui_actId, GonghuiThread.gonghui_count, gonghui_wangyue, GonghuiThread.gonghui_firm_id);
//        task.reportGonghuiListInfo(GonghuiThread.gonghui_actId, GonghuiThread.gonghui_count, gonghui_rongjiali, GonghuiThread.gonghui_firm_id);
//        task.reportGonghuiListInfo(GonghuiThread.gonghui_actId, GonghuiThread.gonghui_count, gonghui_gaobaohong, GonghuiThread.gonghui_firm_id);
        task.reportGonghuiListInfo(GonghuiThread.gonghui_actId, GonghuiThread.gonghui_count, gonghui_wangzhiqiang, GonghuiThread.gonghui_firm_id);
        task.reportGonghuiListInfo(GonghuiThread.gonghui_actId, GonghuiThread.gonghui_count, gonghui_chenzhifei, GonghuiThread.gonghui_firm_id);
        task.reportGonghuiListInfo(GonghuiThread.gonghui_actId, GonghuiThread.gonghui_count, gonghui_liuyanmei, GonghuiThread.gonghui_firm_id);

//        task.reportGonghuiInfo("28356", "1", gonghui_wangyue, GonghuiThread.gonghui_firm_id);
//        task.reportGonghuiInfo("28356", "1", gonghui_rongjiali, GonghuiThread.gonghui_firm_id);
//        task.reportGonghuiInfo("28356", "1", gonghui_gaobaohong, GonghuiThread.gonghui_firm_id);
//        task.reportGonghuiInfo("28356", "1", gonghui_wangzhiqiang, GonghuiThread.gonghui_firm_id);
//        task.reportGonghuiInfo("28356", "1", gonghui_chenzhifei, GonghuiThread.gonghui_firm_id);
//        task.reportGonghuiInfo("28356", "1", gonghui_liuyanmei, GonghuiThread.gonghui_firm_id);

//        task.reportGonghuiInfo("28433", GonghuiThread.gonghui_count, gonghui_rongjiali, GonghuiThread.gonghui_firm_id);
        logger.info("工会任务执行完毕");
    }

    private GongHuiUser copyUser(DianPingUser gaoyang) {
        GongHuiUser gongHuiUser = new GongHuiUser();
        gongHuiUser.setUserName(gaoyang.getUserName());
        gongHuiUser.setLogin_name(gaoyang.getUa());
        gongHuiUser.setReceive_id(gaoyang.getVcode());
        return gongHuiUser;
    }

}